package com.yxhl.zoume.common.presenter;

import android.content.Context;

/**
 * Created by sugarya on 16/5/24.
 * 提供上拉加载的Presenter
 */
public abstract class UpPullPresenter extends BasePresenter {

    /**
     * 当前页数
     */
    private int mCurrentPage = 1;

    public UpPullPresenter(Context context) {
        super(context);
    }

    public int getCurrentPage() {
        return mCurrentPage;
    }

    /**
     * 网络请求成功时的操作
     */
    private void upPullRefreshSuccess() {
        mCurrentPage++;
    }

    /**
     * 网络请求失败时的操作
     */
    protected void upPullRefreshFailure() {
        if (mCurrentPage >= 2) {
            mCurrentPage--;
        }
    }

    /**
     * 上拉加载状态回复初始化
     */
    private void setOriginalUpPullStatus() {
        mCurrentPage = 1;
    }

    public void loadDownRefreshData() {
        setOriginalUpPullStatus();
        loadDataForDownRefresh();
    }

    public void loadUpPullData() {
        upPullRefreshSuccess();
        loadDataForUpPull();
    }


    protected abstract void loadDataForDownRefresh();

    /**
     * 上拉加载网络请求数据
     */
    protected abstract void loadDataForUpPull();

}
